package com.cyl.manager.act.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;


import com.cyl.manager.act.domain.entity.FhDeliveryExpress;
import com.cyl.manager.act.domain.convert.FhDeliveryExpressConvert;
import com.cyl.manager.act.domain.query.FhDeliveryExpressQuery;
import com.cyl.manager.act.domain.vo.FhDeliveryExpressVO;
import com.cyl.manager.act.service.FhDeliveryExpressService;

import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * 快递公司Controller
 *
 * @author zcc
 * @date 2025-09-28
 */
@Api(description ="快递公司接口列表")
@RestController
@RequestMapping("/act/fhDeliveryExpress")
public class FhDeliveryExpressController extends BaseController {
    @Autowired
    private FhDeliveryExpressService service;
    @Autowired
    private FhDeliveryExpressConvert convert;

    @ApiOperation("查询快递公司列表")
    @PreAuthorize("@ss.hasPermi('act:fhDeliveryExpress:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<FhDeliveryExpress>> list(@RequestBody FhDeliveryExpressQuery query, Pageable page) {
        List<FhDeliveryExpress> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出快递公司列表")
    @PreAuthorize("@ss.hasPermi('act:fhDeliveryExpress:export')")
    @Log(title = "快递公司", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(FhDeliveryExpressQuery query) {
        List<FhDeliveryExpress> list = service.selectList(query, null);
        ExcelUtil<FhDeliveryExpressVO> util = new ExcelUtil<>(FhDeliveryExpressVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "快递公司数据"));
    }

    @ApiOperation("获取快递公司详细信息")
    @PreAuthorize("@ss.hasPermi('act:fhDeliveryExpress:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<FhDeliveryExpress> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("新增快递公司")
    @PreAuthorize("@ss.hasPermi('act:fhDeliveryExpress:add')")
    @Log(title = "快递公司", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody FhDeliveryExpress fhDeliveryExpress) {
        return ResponseEntity.ok(service.insert(fhDeliveryExpress));
    }

    @ApiOperation("修改快递公司")
    @PreAuthorize("@ss.hasPermi('act:fhDeliveryExpress:edit')")
    @Log(title = "快递公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody FhDeliveryExpress fhDeliveryExpress) {
        return ResponseEntity.ok(service.update(fhDeliveryExpress));
    }

    @ApiOperation("删除快递公司")
    @PreAuthorize("@ss.hasPermi('act:fhDeliveryExpress:remove')")
    @Log(title = "快递公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
